package com.jimet.process;

import java.util.Hashtable;
import com.jimet.server.JimetServerUser;

public class PageAuthController {

	private Hashtable<String, Hashtable<String, String> > registeredpageAuths;
	public PageAuthController() {
		this.registeredpageAuths	= new Hashtable<String, Hashtable<String, String>>();
		intializePageAuths();
	}
	
	private void intializePageAuths()
	{
		Hashtable<String,String> accountPageHashtable	= new Hashtable<String, String>();
		
		accountPageHashtable.put("100", "USER_MGMT");
		accountPageHashtable.put("101", "USER_MGMT");
		accountPageHashtable.put("102", "USER_MGMT");
		
		registeredpageAuths.put(HeaderPageController.ACCOUNT_PAGE, accountPageHashtable);
	}
	
	public boolean isUserAuthorizedForPage ( JimetServerUser juser , String pg , String pgIx ) throws Exception
	{
		boolean result 	= true;
				
		Hashtable<String,String> tmpAuthsHash	= registeredpageAuths.get(pg);
		if ( tmpAuthsHash != null )
		{
			String strAuthName	= tmpAuthsHash.get(pgIx);
			if ( strAuthName != null )
			{
				result			= juser.isAuthorized(strAuthName);
				if ( juser.isAuthorized("SUPER_USER") )
					result		= true;
			}
 		}
		
		return result;
	}
}
